<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // 1. 计算2 ^ 10
        var num = 1.5;
        console.log(Math.floor(num));
        console.log(Math.ceil(num));
        console.log(Math.round(num)); // 2

        // 1.
        // 输入
        var nums = [1.1, 1.2, 1.3, 1.4];
        // 输出
        var expect = [1, 1, 1, 1];

        function floorNums (nums) {
            var result = [];
            // es6循环数组的方式(不用索引的情况)
            // num是数组项 nums是数组
            for (var num of nums) {
                result.push(Math.floor(num));
            }
            return result;
        }

        // 2.
        // 输入
        var nums = [1.1, 1.2, 1.3, 1.4, 1.5];
        // 输出
        var expect = [1, 1, 1, 1, 2];

        function roundNums (nums) {
            var result = [];
            for (var num of nums) {
                result.push(Math.round(num));
            }
            return result;
        }

        // 随机数
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        console.log(Math.random() * 10);
        // 0 <= r < 1
        // [0, 1)
        // [0, 10)

        // 随机数小练习
        // 生成一个10项的数组，每一项是100以内(0~100)的随机整数
        function getRandomNums () {
            var result = [];
            for (var i = 0; i < 10; i++) {
                var r = Math.random() * 100;
                result.push(Math.round(r));
            }
            return result;
        }

        // 2^2  3^8  4^2
        console.log(Math.pow(2, 10)); // 1024
        // 4 >> 2   9 >> 3   2 >>> 1.414   3 >>> 1.732   5 >>> 2.236
        console.log(Math.sqrt(5));

        // 1 >> 1   2 >>> 2  3 >>> 3   -3 >>> 3  -1 >>> 1
        console.log(Math.abs(-1));

        console.log(Math.PI);

        // 最大最小值
        console.log(Math.max(1, 2, 3)); // 3
        var arr = [1, 2, 3, [1, 2, 3, 4, [1, 2, 3, [1, 2, [[[[[[[[[]]]]]]]]]]]]]; // es6 参数解构
        // var arr = [1, 2, 3, 1, 2, 3, 4]; // 降维
        console.log(arr.flat(Infinity));
        console.log(Math.max(...arr.flat())); // 3
        console.log(Math.min(1, 2, 3, [1, 2, 3, 4])); // 1


    </script>
</body>
</html>